/**
 * 文件夹 视图 页面
 * 使用场景：1、主从数据展示 2、分类数据展示
 */
Rsd.define('Rsd.zen.page.FolderViewPage', {
    extend: 'Rsd.container.Page',
    requires: [
        'Rsd.widget.FolderViewer'
    ],
    xtype: 'folder-page',
    header:false,
    //modelType: 'Rsd.Global.Material.Models.Albums',
    items: [
        {
            xtype: 'folder-viewer',
            header: false,
            width: '100%',
            height: '100%',
            leftLabel: {
                //新增
                position: 'top',
                space: 0,
                id: 'btn_left_label',
                xtype: 'svg', 
                height: 50,   
                label: {
                    content: "&nbsp;&nbsp;分 类",
                    width: 100,
                    space: 0,
                    style: {
                        textAlign:'center', 
                        letterSpacing: '2px',
                    }
                }, 
                ctrlStyle:{margin:'0 10px 0 10px'},
                dataSource: {
                    viewBox: '0 0 1024 1024',
                    paths:  [
                        "M720 192c-8.853333 0-16 7.146667-16 16s7.146667 16 16 16h32c8.853333 0 16-7.146667 16-16s-7.146667-16-16-16h-32zM608 208c0-8.853333-7.146667-16-16-16H240c-8.853333 0-16 7.146667-16 16s7.146667 16 16 16h352c8.853333 0 16-7.146667 16-16z",
                        "M400 928H176c-26.453333 0-48-21.546667-48-48V112c0-26.453333 21.546667-48 48-48h640c26.453333 0 48 21.546667 48 48v292.053333c0 8.853333 7.146667 16 16 16s16-7.146667 16-16V112c0-44.16-35.84-80-80-80H176c-44.16 0-80 35.84-80 80v768c0 44.16 35.84 80 80 80h224c8.853333 0 16-7.146667 16-16s-7.146667-16-16-16z",
                        "M720 601.706667c-71.573333 0-129.813333 58.24-129.813333 129.813333S648.426667 861.333333 720 861.333333s129.813333-58.24 129.813333-129.813333c0-71.68-58.24-129.813333-129.813333-129.813333z m0 227.52c-53.866667 0-97.813333-43.84-97.813333-97.813334S666.026667 633.6 720 633.6s97.813333 43.84 97.813333 97.813333-43.946667 97.813333-97.813333 97.813334z",
                        "M985.386667 672.746667l-1.813334-8.213334-7.893333-3.093333c-23.36-9.386667-42.24-25.386667-54.293333-46.4-12.053333-20.906667-16.533333-45.12-13.013334-69.973333l1.173334-8.32-6.293334-5.653334c-29.653333-27.093333-65.173333-47.573333-102.933333-59.2l-7.893333-2.453333-6.506667 5.013333c-39.04 29.653333-93.013333 29.653333-132.053333 0l-6.506667-5.013333-7.893333 2.453333c-38.186667 11.733333-74.133333 32.533333-103.893334 60.16l-5.973333 5.546667 0.853333 8.106667c2.666667 23.786667-1.92 46.933333-13.546666 66.986666-11.84 20.373333-29.866667 36.16-52.373334 45.653334l-7.466666 3.2-1.813334 7.893333c-4.906667 20.693333-7.36 41.706667-7.36 62.4 0 18.88 2.133333 38.186667 6.293334 57.493333l1.706666 8.106667 7.573334 3.2c22.186667 9.493333 40.106667 25.28 51.84 45.546667 12.053333 20.8 16.533333 44.8 13.12 69.546666l-1.173334 8.106667 5.973334 5.653333c29.546667 27.84 63.786667 48.32 101.76 60.693334l8.106666 2.666666 6.72-5.226666c40-31.04 95.68-30.613333 135.146667 1.173333l6.613333 5.333333 8.106667-2.56c38.08-11.84 72.32-31.253333 101.866667-57.92l6.4-5.76-1.28-8.533333c-3.733333-25.173333 0.746667-49.6 13.013333-70.72 12.373333-21.44 31.68-37.653333 55.68-46.933333l8.106667-3.093334 1.813333-8.426666c4.266667-19.52 6.506667-39.146667 6.506667-58.56 0.213333-19.413333-2.026667-39.146667-6.4-58.88z m-29.44 102.4c-27.093333 12.266667-49.066667 32-63.68 57.386666-14.4 24.853333-20.586667 53.333333-17.92 82.56-22.613333 18.986667-48.106667 33.493333-76.053334 43.2-24.213333-17.28-52.16-26.346667-81.28-26.346666-28.373333 0-55.573333 8.64-79.36 24.96-28.053333-10.24-53.653333-25.6-76.266666-45.653334 2.346667-28.8-3.84-56.746667-18.026667-81.386666-13.76-23.893333-34.133333-42.88-59.2-55.36-2.666667-14.506667-4.053333-28.906667-4.053333-42.986667 0-15.786667 1.6-31.68 4.8-47.573333 25.386667-12.373333 45.973333-31.573333 59.946666-55.68 13.653333-23.68 19.946667-50.56 18.453334-78.186667 23.146667-20.053333 50.026667-35.626667 78.506666-45.546667 47.04 31.786667 109.76 31.786667 156.8 0 27.946667 9.706667 54.4 24.96 77.333334 44.48-2.453333 29.013333 3.733333 57.066667 18.026666 81.813334 14.293333 24.746667 35.626667 44.266667 62.08 56.64 2.773333 14.826667 4.16 29.546667 4.16 43.946666-0.213333 14.506667-1.6 29.12-4.266666 43.733334zM640 144v128c0 8.853333 7.146667 16 16 16s16-7.146667 16-16V144c0-8.853333-7.146667-16-16-16s-16 7.146667-16 16zM768 400c0-8.853333-7.146667-16-16-16H432c-8.853333 0-16 7.146667-16 16s7.146667 16 16 16h320c8.853333 0 16-7.146667 16-16zM240 384c-8.853333 0-16 7.146667-16 16s7.146667 16 16 16h64c8.853333 0 16-7.146667 16-16s-7.146667-16-16-16h-64zM352 336v128c0 8.853333 7.146667 16 16 16s16-7.146667 16-16V336c0-8.853333-7.146667-16-16-16s-16 7.146667-16 16z"
                    ],
                    fill:"#1296db"
                }, 
                tip:'管理相册信息',
                handler: 'btn_left_mgr'
               
            },
            contentHeader: {
                header:{
                    position: 'left',
                    space: 0,
                    content: '文件列表',
                    width: 100,
                    align: 'left',
                    style: {
                        fontSize: '120%',
                        backgroundColor: 'transparent',
                        letterSpacing: '2px',
                    }
                }, 
                layout:{type:'hbox',align:'right'},
                items: [  
                    {
                        xtype: 'svg',
                        label: false,
                        width: 40,
                        dataSource: 'icon.vline'
                    },
                    {
                        name: 'btn_list',
                        xtype: 'svg',
                        label: false,
                        margin: '0 10 0 0',
                        height: 30,
                        width: 30,
                        style: {
                            boxSizing: 'border-box',
                            border: '1px #e9ebf4 solid',
                            color: "#0b2cee"
                        },
                        tip: '缩略图方式展示',
                        dataSource: {
                            viewBox: "0 0 1024 1024",
                            path: "M240.941176 271.058824a30.117647 30.117647 0 0 1 30.117648-30.117648h180.705882a30.117647 30.117647 0 0 1 30.117647 30.117648v180.705882a30.117647 30.117647 0 0 1-30.117647 30.117647H271.058824a30.117647 30.117647 0 0 1-30.117648-30.117647V271.058824z m60.235295 30.117647v120.470588h120.470588v-120.470588h-120.470588zM542.117647 271.058824a30.117647 30.117647 0 0 1 30.117647-30.117648h180.705882a30.117647 30.117647 0 0 1 30.117648 30.117648v180.705882a30.117647 30.117647 0 0 1-30.117648 30.117647h-180.705882a30.117647 30.117647 0 0 1-30.117647-30.117647V271.058824z m60.235294 30.117647v120.470588h120.470588v-120.470588h-120.470588zM542.117647 572.235294a30.117647 30.117647 0 0 1 30.117647-30.117647h180.705882a30.117647 30.117647 0 0 1 30.117648 30.117647v180.705882a30.117647 30.117647 0 0 1-30.117648 30.117648h-180.705882a30.117647 30.117647 0 0 1-30.117647-30.117648v-180.705882z m60.235294 30.117647v120.470588h120.470588v-120.470588h-120.470588zM240.941176 572.235294a30.117647 30.117647 0 0 1 30.117648-30.117647h180.705882a30.117647 30.117647 0 0 1 30.117647 30.117647v180.705882a30.117647 30.117647 0 0 1-30.117647 30.117648H271.058824a30.117647 30.117647 0 0 1-30.117648-30.117648v-180.705882z m60.235295 30.117647v120.470588h120.470588v-120.470588h-120.470588z",

                        },
                        handler: 'btn_show_list'
                    },
                    {
                        name: 'btn_grid',
                        xtype: 'svg',
                        label: false,
                        margin: '0 0 0 0',
                        height: 30,
                        width: 30,
                        style: {
                            boxSizing: 'border-box',
                            color: "#8C8C8C"
                        },
                        tip: '列表方式展示',
                        dataSource: {
                            viewBox: "0 0 1024 1024",
                            paths: [
                                "M170.666667 298.666667m-42.666667 0a42.666667 42.666667 0 1 0 85.333333 0 42.666667 42.666667 0 1 0-85.333333 0Z",
                                "M170.666667 512m-42.666667 0a42.666667 42.666667 0 1 0 85.333333 0 42.666667 42.666667 0 1 0-85.333333 0Z",
                                "M170.666667 725.333333m-42.666667 0a42.666667 42.666667 0 1 0 85.333333 0 42.666667 42.666667 0 1 0-85.333333 0Z",
                                "M298.666667 469.333333m40.106666 0l517.12 0q40.106667 0 40.106667 40.106667l0 5.12q0 40.106667-40.106667 40.106667l-517.12 0q-40.106667 0-40.106666-40.106667l0-5.12q0-40.106667 40.106666-40.106667Z",
                                "M298.666667 682.666667m40.106666 0l517.12 0q40.106667 0 40.106667 40.106666l0 5.12q0 40.106667-40.106667 40.106667l-517.12 0q-40.106667 0-40.106666-40.106667l0-5.12q0-40.106667 40.106666-40.106666Z",
                                "M298.666667 256m40.106666 0l517.12 0q40.106667 0 40.106667 40.106667l0 5.12q0 40.106667-40.106667 40.106666l-517.12 0q-40.106667 0-40.106666-40.106666l0-5.12q0-40.106667 40.106666-40.106667Z"
                            ],
                        },
                        handler: 'btn_show_grid'
                    },
                    {
                        xtype: 'svg',
                        label: false,
                        margin: '0 40 0 0',
                        width: 40,
                        dataSource: 'icon.vline'
                    },
                    {
                        xtype: 'text',
                        name:'keywords',
                        label: '关键字'
                    },
                    {
                        xtype: 'button',
                        text: '查 询',
                        handler: '_btn_search'
                    }
                ]
            },
            left:{},
            content:{},
            contentColumns: [],
            leftItemDblClickHandler: 'left_item_dblClick',
            fileItemDblClickHandler: 'file_item_dblClick',
            rowDblClickHandler:'row_dbl_click',
            pageIndexChangedHandler: 'pageIndexChanged',
        },
        {
            id: 'btn_add_file',
            xtype: 'svg',
            width: 28,
            height: 28,
            floating: true,
            label: false,
            style: {
                right: '30px',
                bottom: '50px'
            },
            dataSource: {
                viewBox: '0 0 1024 1024',
                path: "M512 1024C229.216 1024 0 794.784 0 512S229.216 0 512 0s512 229.216 512 512-229.216 512-512 512z m0-960C264.576 64 64 264.576 64 512s200.576 448 448 448 448-200.576 448-448S759.424 64 512 64z m192 480h-160v160a32 32 0 0 1-64 0v-160h-160a32 32 0 0 1 0-64h160v-160a32 32 0 0 1 64 0v160h160a32 32 0 0 1 0 64z"
            },
            listeners: {
                mouseover: {
                    element: 'ctrl',
                    fn: function (sender, event) {
                        this.ctrl.element.style.shadow = '2px 2px 2px 2px';
                        this.ctrl.element.style.scale = 1.2;
                        this.ctrl.element.style.color = 'red';
                        this.ctrl.element.style.cursor = 'pointer';
                    }
                },
                mouseout: {
                    element: 'ctrl',
                    fn: function (sender, event) {
                        this.ctrl.element.style.scale = 1;
                        this.ctrl.element.style.color = 'grey';
                        this.ctrl.element.style.cursor = 'inherit';
                    }
                }

            },
            tip: '新增一个对象',
            handler: 'btn_new_file'
        },
    ],
    /**
     * 
     */
    folderImageUrl: './resources/images/control/folder-2-close.png',
    /**
     * 
     */
    openFolderImageUrl: './resources/images/control/folder-2-open.png',
    /**
     * 文件对象模板
     */
    fileItemTemplate:{}, 
    /**
     * 
     */
    leftItemTemplate:{}, 
    /**
     * 
     */
    constructor: function FolderViewPage(config) {
        config = config || {};
        this.apply(config);  
    },
    /**
     * 
     */
    onBeforeInit:function onBeforeInit()
    {
        if(this.menu)
        {
            this.readonly = this.menu.readonly == undefined ? this.readonly : this.menu.readonly;
            this.modelType = this.modelType || this.menu.modelType;
        
            this.columns = this.columns || this.menu.columns || [];
            this.searchColumns = this.searchColumns || this.menu.searchColumns||[];
            this.newButtons = this.menu.newButtons||[]; 

            this.serviceName =  this.serviceName || this.menu.serviceName; 
            this.listMember = this.listMember || this.menu.listMember || 'rows';
            this.where = this.where || this.menu.where||[]
            this.sort = this.sort || this.menu.sort||[];
 
            if(this.menu.formTitle)
            {
                this.form.title = this.menu.formTitle;
            }
            if(this.menu.formModelType)
            {
                this.form.modelType = this.menu.formModelType;
            }
        }

        this.callParent();
    },
    /** 
     args :api 接口需要的参数
     只加载content 内容，不加载 左侧内容
    *
    * */
    load:function load(args,callback) {        
        this.callParent();
        //debugger;
        var me = this;
         
        if(Rsd.isArray(args))
        {  
            me.loadContent([],args,callback);
            return;
        }

        if(!me.dataStore)
        {
             var _serviceName = me.serviceName || (me.modelSchema && me.modelSchema.listService); 
            if(!Rsd.isEmpty(_serviceName))
            {  
                var _service = Rsd.app.getService(_serviceName);
                if(_service)
                {
                    me.dataStore = Rsd.create('Rsd.data.Store',{proxy:_service,listName:me.listMember || 'rows'}); 
                } 
            }
        }  
       
        if(me.dataStore)
        {  
            Rsd.showWaiting(me.id, me);
            setTimeout(function () {

                var opt = me.getPagingOpt();
                var _args = Rsd.apply(args || {}, {
                    modelType: me.modelType || '',
                    pageSize: opt.pageSize || 100,
                    pageIndex: opt.pageIndex || 0,
                });

                _args.where = Rsd.arrayConcat(_args.where, me.where, me.toolBar && me.toolBar.getWhere()),
                    _args.sort = Rsd.arrayConcat(_args.sort, me.sort);

                me.dataStore.load(_args, function (resp) {

                    if (resp && resp.success) {
                        var _data = resp.data || {};
                        if (Rsd.isArray(_data)) {
                            me.setPagingOpt({ pageSize: opt.pageSize, pageIndex: 0, pageCount: 1, totalCount: _data.length });
                        }
                        else {
                            me.setPagingOpt({ pageSize: _data.pagesize || 100, pageIndex: _data.pageindex || 0, pageCount: _data.pagecount || 0, totalCount: _data.total || 0 });
                        }
                    }
                    me.loadContent(_data[me.listMember],callback);
                  
                    Rsd.closeWaiting(me.id);
                     
                    return ;
                });

            }, 50);
        }
    },
    
    /**
     *   
     * @param {*} rows 数据记录
     * @param {*} callback 回调方法
     */
    loadLeft:function loadLeft(rows,callback)
    {
        var me = this;
        var listItems = [];
        for(var i in rows)
        {
            var row = rows[i];
            var item = {
                key: '',
                width: '100%',
                height: '90%',
                readonly: true,
                toolbar: false,
                showLoadingBar: false,
                label: {
                    position: 'bottom',
                    xtype: 'link',
                    label:false,
                    text: '',
                    height: 'auto',
                    space: 10,
                    width: '100%',
                    style: {  
                        lineHeight:'20px',
                        //minHeight:40,
                        maxHeight:40,
                        "textAlign": "center" 
                    },
                    handler: '',
                    ctrlTagName: 'a'
                },
                src:'',
                backgroundImage:'', 
                tip:'',
                data: row
            };
            Rsd.apply(item,Rsd.template(me.leftItemTemplate||{},row),2);       
            listItems.push(item);
        }
        this.items[0].loadLeft(listItems,callback);
    },
    /**
     * 
     * @param {*} rows 数据记录
     * @param {*} callback 回调方法
     */
    loadContent: function loadContent(rows,callback) {

        var me = this;
        var listItems = [];
        //console.log('load content',rows);
        for (var i in rows) {
            var row = rows[i];
            var item = {
                height: '100%',
                width: '96%',
                label: {
                    content: '',
                    position: 'bottom',
                    space: 0,
                    height: 50,
                    style: { whiteSpace: 'wrap', overflow: 'hidden' }
                },
                readonly: true,
                toolbar: false,
                checkbox: me.showCheckbox,
                oncheckedchange: function (sender, e) {

                    if (me.multiple) { }
                    else {
                        //处理单选
                        var list = Rsd.select(me.items[1].dom, 'li>div>input:checked');
                        list.forEach(function (p) {
                            if (p != e.target) {
                                p.checked = false;
                            }
                        });
                        //console.log(list);
                    }
                    //console.log(e.target.checked,e.target.value);

                },
                showLoadingBar: false,
                tip: '',
                style: { marginLeft: '2%' },
                backgroundImage: '',
                data: row
            };
            Rsd.apply(item,Rsd.template(me.fileItemTemplate||{},row),2);
            listItems.push(item); 
        }

        this.items[0].loadContent(listItems,rows);

        var _f = Rsd.callFunction(me, callback || function (__data) {

            if (__data === undefined || __data === null) {
                Rsd.alert('数据加载失败', '未获取到数据（网络故障）。');
                return false;
            }
            if (Rsd.isArray(__data)) {
                return true;
            }
            if (__data.success) { }
            else {

                if (Rsd.isEmpty(__data.msg)) {
                    console.error('未知错误(UI0009),请查看日志。', resp);
                }

                return true;
            }

            return true;

        }, arguments);
    },
    /**
     * 
     * @param {*} row 
     * @param {*} readonly 
     * @returns 
     */
    createFormDialog:function createFormDialog(row,readonly)
    { 
        var _schema = this.formSchema||this.modelSchema;
         
        var _form = this.form||{};  //form 配置项
        var _title = "";
        //优先使用 formTitle
        var _tplStr = this.form.title || _form.title||null;
        if(Rsd.isEmpty(_tplStr))
        {  
            var _titleField = _form.titleField|| this.titleMember || (_schema&&_schema.titleField);
            _tplStr =  ( _tplStr ||'详细信息') + "-[{{=("+_titleField+"||\'*\')}}]";
        }
        if(_tplStr)
        {
            try
            { 
                _title = Rsd.template(_tplStr,row||{}); 
            }
            catch(err)
            {
                _title = _tplStr;
                console.error(err);
            }
        } 
        else
        {
            _title = "详细信息(未设置formTitle)";
        }
        
        var _height = _form.height||(500+120);
        var _width = _form.width||(680+100);
        
        var _buttons = _form.buttons;
        
        //console.log(_buttons);
        var _viewType = _form.viewType||'Rsd.zen.dialog.FormDialog';
        var _fields = this.formFields||[]; 
        if(_fields.length==0)
        {
            _fields = _form.fields||[]; 
        }
        if(_fields.length==0)
        {
            _fields = _schema.fields||[];
        }
        
        return Rsd.create(_viewType, {
            title: _title||_tplStr,
            formHeight:'auto',
            formFields:_fields, 
            fieldWidth:this.form.fieldWidth||'45%',
            modelSchema:_schema,
            parent:this,
            readonly:readonly,
            buttons:_buttons,
            height:_height,
            width:_width,
            data:row, 
        });
 
    },
    /**
     *  @description 展示row数据
     */
    showItem:function showItem(row)
     {
        var readonly = this.readonly;//data['readonly'];
        var form = this.createFormDialog(row,readonly); 
         
        switch (this.form.position) {

            case "left":
                form.showDialogOnLeft();
                break;
            case "right":
                form.showDialogOnRight();
                break;
            default:
                form.showDialog();
                break;
        } 
    },
    /** 
    * @private
    * */
    buildGridColumns:function buildGridColumns() {
        var me = this;
        var _cols = [];
        Array.prototype.push.apply(_cols, this.gridColumns||[]);
        Array.prototype.push.apply(_cols, this.opColumns||[])

        //为列自动关联format方法
        for(var i in _cols)
        {
            var c = _cols[i]; 
            if(!c || c.format)
            {
                continue;
            }
            if(this['format'+c.name])
            {
                c.format = 'format' + c.name; 
            }
        } 
        if(me.items[0] instanceof Rsd.widget.FolderViewer)
        {
             var grid = me.items[0].items[1].items[1];
            grid.buildColumns(_cols);
            return;
        }
      
        me.items[0].contentColumns = _cols;
    },
    /**
     * 新增 文件按钮点击
     */
    btn_new_file: function btn_new_file(sender, evt) {

        this.showItem(sender.data||{});
    },
    /**
    * 
    */
    _btn_search:function _btn_search() {

        //友好做法时：在查询条件发发生改变时，设置分页 {pageIndex: 0}
        if(this.whereIsChange())
        {
            this.setPagingOpt({pageIndex:0});
        }

        this.load({});
    }, 
    /**
    * 
    * */
    whereIsChange:function whereIsChange() {
 
        var _where = this.toolBar&&this.toolBar.getWhere();
        if (Rsd.isEmpty(this.____lastWhere) && Rsd.isEmpty(_where)) {
            return false;
        }
        if (Rsd.isEmpty(this.____lastWhere) || !Rsd.isEmpty(_where)) {
            return true;
        }
        if (!Rsd.isEmpty(this.____lastWhere) || Rsd.isEmpty(_where)) {
            return true;
        }
        if (this.____lastWhere.length  != _where.length) {
            return true;
        }
        for(var i in _where)
        {

        }
        return true;
    },
    /*
     * */
    pageIndexChanged: function pageIndexChanged(pagingOpt) {
        //debugger;

        this.load({});//只需重新加载，pagingOpt 信息自动获取

    },
    /**
    * @description 获取分页信息,在查询时，自动加上分页信息
    * */
    getPagingOpt:function getPagingOpt() { 
        
      return this.items[0].getPagingOpt();
    },

    /**
    * @description 设置分页信息,一般在查询条件发发生改变时，需重新设置分页 {pageIndex: 0}
    * */
    setPagingOpt:function setPagingOpt(opt) {

       return this.items[0].setPagingOpt(opt);
    },
    /***
     * 
     */
    left_item_dblClick:function left_item_dblClick(sender,evt,config)
    {
        if (this.currentItem && this.currentItem != sender) {
            this.currentItem.setSrc(this.folderImageUrl);
        }
        this.currentItem = sender;
        sender.setSrc(this.openFolderImageUrl);

        if(this.leftItemDblClickHandler)
        {
            this.funApplyByIOC(this.leftItemDblClickHandler, [sender, evt,config]);
        }
    },
    /**
     * 
     * @param {*} sender 
     * @param {*} evt 
     * @param {*} config 
     */
    file_item_dblClick:function file_item_dblClick(sender,evt,config)
    {
        if(this.fileItemDblClickHandler)
        {
            this.funApplyByIOC(this.fileItemDblClickHandler, [sender, evt,config]);
        }
    },
    /**
     * 
     * @param {*} row 
     * @param {*} evt 
     * @param {*} data 
     */
    row_dbl_click:function row_dbl_click(row,evt,data)
    {
        this.showItem(row);
    },
    /**
     * 
     * @param {*} sender 
     * @param {*} evt 
     */
    btn_show_list: function btn_show_list(sender, evt) {
        this.items[0].showList();
        sender.setElStyle('dom', { border: '1px #e9ebf4 solid', color: "#0b2cee" });
        sender.parent.getItemByName('btn_grid').setElStyle('dom', { border: '0px', color: "#8C8C8C" });
    },
    /**
     * 
     * @param {*} sender 
     * @param {*} evt 
     */
    btn_show_grid: function btn_show_grid(sender, evt) {
        this.items[0].showGrid();
        sender.setElStyle('dom', { border: '1px #e9ebf4 solid', color: "#0b2cee" });
        sender.parent.getItemByName('btn_list').setElStyle('dom', { border: '0px', color: "#8C8C8C" });
    },
    
    /**
     * 本地表格数据导出excel
     * @param {*} sheet 
     * @param {*} file 仅文件名称（不是路径）
     */
    "export": function _export(sheet,file) {
        var grid = me.items[0].items[1].items[1];
        grid.export(sheet,file);
    }
      
},function(type){
    //leftLabel
    var _leftLabelGetter = function () {
 
        return this.items[0].leftLabel;
    };

    var _leftLabelSetter = function (value) {

        if(Rsd.isObject(value))
        {
            Rsd.apply(this.items[0].leftLabel,value,2);
        }
        if(Rsd.isString(value))
        {
            this.items[0].leftLabel.label.content = value; 
        }
        if(Rsd.isBoolean(value))
        {
            this.items[0].leftLabel.label = value; 
        }
        
    };
    this.defineProperty(type, "leftLabel", _leftLabelGetter, _leftLabelSetter, false);
    
    //toolBar
    var _toolBarGetter = function () {
 
        return this.items[0].contentHeader.content;
    };

    var _toolBarSetter = function (value) {
        
        if(Rsd.isObject(value))
        {
            Rsd.apply(this.items[0].contentHeader.header,value,2); 
        }
        if(Rsd.isString(value))
        {
            this.items[0].contentHeader.header.content = value; 
        }
        if(Rsd.isBoolean(value))
        {
            this.items[0].contentHeader.header = value; 
        }
    };
    this.defineProperty(type, "toolBar", _toolBarGetter, _toolBarSetter, false);
  
    
    //newButtons
    var _newButtonsGetter = function () {
       
        if(!this.hasOwnProperty('__newButtons'))
        {
            this.__newButtons = [];
        }
        
        return this.__newButtons;
    };

    var _newButtonsSetter = function (value) {
        var _value = value||[];    
        if(_value == this.__newButtons)
        {
            return;
        }
        this.__newButtons = _value; 
        this.items[0].contentHeader.items = Rsd.arrayConcat(_value,this.items[0].contentHeader.items);
    }

    this.defineProperty(type,"newButtons", _newButtonsGetter, _newButtonsSetter,true);

    //searchColumns
    var _searchColumnsGetter = function _searchColumnsGetter() { 
         
        if(!this.__searchColumns)
        {
            this.__searchColumns = [] ;
        }

        return this.__searchColumns;
    }

    var _searchColumnsSetter = function _searchColumnsSetter(value) { 
            
        this.__searchColumns = value||[]; 
     }

    this.defineProperty(type,"searchColumns", _searchColumnsGetter, _searchColumnsSetter,true);
    //formFields
    var _formFieldsGetter = function () {
        if (this.__formFields == undefined) {
            this.__formFields = [];
        }
        return this.__formFields;
    };

    var _formFieldsSetter = function (value) {
        this.__formFields = value;
    }

    this.defineProperty(type, "formFields", _formFieldsGetter, _formFieldsSetter, true);

    //gridColumns
    var _gridColumnsGetter = function () {
        if(this.__gridColumns == undefined)
        {
            this.__gridColumns = [];
        }
        return this.__gridColumns;
    };

    var _gridColumnsSetter = function (value) {
        this.__gridColumns = value; 
        this.buildGridColumns();
    }
    this.defineProperty(type, "gridColumns", _gridColumnsGetter, _gridColumnsSetter, false);

    //opColumns
    var _opColumnsGetter = function () {

        return this.__opColumns||[];
    };

    var _opColumnsSetter = function (value) {

        this.__opColumns = value; 
        this.buildGridColumns();
    }

    this.defineProperty(type,"opColumns", _opColumnsGetter, _opColumnsSetter,true);
  
    
    //left
    var _leftGetter = function () {
 
        return this.items[0].left;
    };
    var _leftSetter = function (value)
    {
         if(Rsd.isObject(value))
         {
            Rsd.apply(this.items[0].left,value,2); 
         }
         
    }
    this.defineProperty(type, "left", _leftGetter, _leftSetter, false);
    
    //content
    var _contentGetter = function (value) {
         return this.items[0].content;
    }; 
    var _contentSetter = function (value)
    {
        if(Rsd.isObject(value))
         {
             Rsd.apply(this.items[0].content,value,2);
         }
        
    }
    this.defineProperty(type, "content", _contentGetter, _contentSetter, false);
    

    //add button
    var _addButtonGetter = function (value) {
         return this.items[1];
    }; 
    var _addButtonSetter = function (value)
    {
        if(Rsd.isString(value))
        {
             this.items[1].tip = value;
        }
        if(Rsd.isBoolean(value))
        {
             this.items[1].visible = value;
        }
        if(Rsd.isObject(value))
        {
            Rsd.apply(this.items[1],value);
        } 
    }
    this.defineProperty(type, "addButton", _addButtonGetter, _addButtonSetter, false);
    //
    var _formGetter = function _formGetter()
    {
        if(Rsd.isEmpty(this.__form))
        {
            this.__form = {
                viewType:'Rsd.zen.dialog.FormDialog',//明细窗体类型
                modelType:this.modelType,
                fields:null,
                fieldWidth:'45%',//form 字段默认宽度
                titleField:'',
                title:'',
                height:'auto',//form 窗体高度
                width:'60%', //form 窗体宽度
                position:'center', //表单展示位置 center,left,right  
                buttons:['save','delete','cancel'],//form 表单底部buttons
                data:{}//新增时 form默认数据 
            };
        }

       return this.__form;
    };

    var _formSetter  =function _formSetter(value)
    {
        if(Rsd.isString(value))
        {
            this.form.viewType = value;
            return;
        }
       
        if(Rsd.isObject(value))
        {
            Rsd.apply(this.form,value);
            return;
        }
        
    }

    this.defineProperty(type,"form", _formGetter, _formSetter,true);
});